<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/static/xadmin/css/font.css">
    <link rel="stylesheet" href="/static/xadmin/css/xadmin.css">
    <link rel="stylesheet" href="/static/css/apublic.css">
    <script src="/static/xadmin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/xadmin/js/xadmin.js"></script>
    <!--[if lt IE 9]>
    <script src="/static/xadmin/html5.min.js"></script>
    <script src="/static/xadmin/respond.min.js"></script>
    <![endif]-->
    <script src="/static/until.js" charset="utf-8"></script>
    <script>
        if(!sessionStorage.getItem('token')) window.top.location.href='/login.html';
    </script>
</head>
<body>
<div class="layui-fluid check-layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body check-layui-card-body">
                    
                </div>
                <div class="layui-card-body check-layui-card-body">
                    <table id="mytable" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="barDemo">
    {{# if (d.id == getQueryString("id") || none.indexOf(","+d.parent_id+",")>=0) { 
        none+=d.id+",";
    }}  
    {{# } else { }} 
    <a class="layui-btn layui-btn-xs" lay-event="detail">选择</a>
    {{# } }}
</script>
<script>
    var check_url=baseUrl+"/goodsclass/list";
    var table
    var none=","
    layui.config({
        base: '/static/treetable-lay/'
    }).use(['treeTable'], function () {
        table = layui.treeTable;
        table.render({
            elem: '#mytable',
            url: check_url,
            method: 'post',
            headers:{token:sessionStorage.getItem('token')},
            page:true,
            tree: {
                iconIndex: 1,                // 折叠图标显示在第几列
                idName: 'id',       // 自定义id字段的名称
                pidName: 'parent_id',         // 自定义标识是否还有子节点的字段名称
                haveChildName: 'haveChild',  // 自定义标识是否还有子节点的字段名称
                isPidData: true              // 是否是pid形式数据
            },
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.status.errorCode, //解析接口状态
                    "msg": res.status.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            },
            cols: [[ //标题栏
                {field: 'id', title: 'ID', width: "5%"}
                , {field: 'title', title: '标题', width: "50%"}
                , {field: 'right', title: '操作', width: "20%",toolbar: '#barDemo'}
            ]],
            done: function (res, curr, count) {
                $("table").css("width", "100%");
            },
        });
        //监听工具条,,行内
        table.on('tool(mytable)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            if(layEvent === 'detail'){ //查看
                //do somehing
                if(window.parent.setparent(data.id,data.title)){
                    xadmin.close();
                }
            }
        });
    });
</script>
</html>

